package com.vastdata.spring.jdbc.dao;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Getter
@Repository
public class SampleDao {

    private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SampleDao.class);

    private JdbcTemplate jdbcTemplate;

    public boolean execute(String sql, String[] args) {
        try {
            int update = jdbcTemplate.update(sql, args);
            return update != 0;
        } catch (Exception e) {
            logger.error("execute sql error：{1}", sql, e);
            return false;
        }
    }

    public List<Map<String, Object>> query(String sql, Object[] args) {
        return jdbcTemplate.queryForList(sql, args);
    }

}
